﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Windows.Forms;
using Microsoft.VisualBasic.FileIO;
using DXWindowsApplication1.MainForm;

namespace DXWindowsApplication1.MainForm
{
    public class TreeViewExplorer
    {
        public string _path = ""; // Lưu đường dẫn của thư mục

        Support support = new Support();

        public void buildTree(TreeView treeview)
        {

            TreeNode nodeMyComputer = new TreeNode();
            nodeMyComputer.Text = "My Computer";
            nodeMyComputer.ImageIndex = 2;
            nodeMyComputer.SelectedImageIndex = 2;
            treeview.Nodes.Add(nodeMyComputer);
            foreach (DriveInfo drvinfo in DriveInfo.GetDrives())
            {
                TreeNode nodeDrive = new TreeNode();
                nodeDrive.Text = drvinfo.Name;
                nodeDrive.ImageIndex = support.driveImage(drvinfo);
                nodeDrive.SelectedImageIndex = support.driveImage(drvinfo);
                nodeDrive.Nodes.Add("temp");
                 nodeMyComputer.Nodes.Add(nodeDrive);
            }

        }
        public void expandTree(TreeNode node)
        {
            DirectoryInfo dirinfo = new DirectoryInfo(support.getPathDirectories(node));
            node.Nodes.Clear();
            try
            {
                foreach (DirectoryInfo dir in dirinfo.GetDirectories())
                {
                    TreeNode treenode = new TreeNode();
                    treenode.Text = dir.Name;
                    treenode.ImageIndex = 1;
                    treenode.SelectedImageIndex = 0;
                    treenode.Nodes.Add("temp");
                    node.Nodes.Add(treenode);
                }
            }
            catch
            {
                MessageBox.Show("Truy cập bị từ chối", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }    

    }
}

